<template>
	<block>
		<view v-for="(item,index) in mediaList" :key="index" class="hxt-card">
			<view class="hxt-flex" style="padding-bottom: 10rpx;">
				<view class="hxt-flex-fill"></view>
				<view class="bg-white line-gray solid round">
					<view @click="mediaChange('up', item, index)" v-if="index!=0" class="btn">上移</view>
					<view @click="mediaChange('down', item, index)" v-if="index!=mediaList.length-1" class="btn">下移
					</view>
					<view @click="mediaChange('del', item, index)" class="btn">删除</view>
					<hxt-dropbutton>
						<view class="btn">插入</view>
						<block slot="items">
							<view class="md-tag bg-white">
								<view @click="addMedia({type:1,item:item,index:index})" class="cu-capsule"
									style="padding-left: 30rpx;">
									<view class="cu-tag bg-blue">
										<text class="fa fa-file-text-o"></text>
									</view>
									<view class="cu-tag line-blue">文字</view>
								</view>
								<view @click="sheetFile({type:2,item:item,index:index})" class="cu-capsule">
									<view class="cu-tag bg-blue">
										<text class="fa fa-file-image-o"></text>
									</view>
									<view class="cu-tag line-blue">图片</view>
								</view>
								<view @click="sheetFile({type:3,item:item,index:index})" class="cu-capsule">
									<view class="cu-tag bg-blue">
										<text class="fa fa-file-audio-o"></text>
									</view>
									<view class="cu-tag line-blue">音频</view>
								</view>
								<view @click="sheetFile({type:4,item:item,index:index})" class="cu-capsule">
									<view class="cu-tag bg-blue">
										<text class="fa fa-file-video-o"></text>
									</view>
									<view class="cu-tag line-blue">视频</view>
								</view>
								<view @click="sheetFile({type:7,item:item,index:index})" class="cu-capsule">
									<view class="cu-tag bg-blue">
										<text class="fa fa-file-pdf-o"></text>
									</view>
									<view class="cu-tag line-blue">文件</view>
								</view>
							</view>
						</block>
					</hxt-dropbutton>

				</view>
			</view>
			<hxt-input v-if="item.miType==1" type="textarea" input-class="input-class" class="hxt-flex-fill"
				placeholder="请输入内容" v-model="item.miTitle" maxlength="1000" show-word-limit clearable />
			<block v-else-if="item.miType==2">
				<!-- <view style="width: 100%;">
					<view style="padding-top:100%;position:relative;">
						<image :src="item.miUrl" lazy-load="true" style="position:absolute; width:100%;height:100%;left:0; top:0; z-index: 1;"></image>
					</view>
				</view> -->
				<van-image width="100%" height="300" fit="contain" lazy-load :src="!!item.rawUrl?item.rawUrl:item.miUrl"
					@click="previewImage(item.miUrl)" />
			</block>
			<block v-else-if="item.miType==3">
				<view class="cu-list menu-avatar padding-top-xs" style="overflow-x: hidden; overflow-y: auto;">
					<view class="cu-item"
						style="background: #f3f3f3; border-radius: 8rpx; margin: 8rpx 0; height: 100rpx;">
						<view class="cu-avatar" style="background-color: #f3f3f3;">
							<i class="fa" :class="[item.isPlay?'fa-pause-circle-o':'fa-play-circle']"
								@click="playAudio(index)"
								style="color: #00b1ff;font-size: 64rpx; margin-right: 12rpx;"></i>
						</view>
						<view class="content" style="left: 115rpx; width: calc(100% - 96rpx - 170rpx);">
							<slider @change="swiperChange" :value="item.value" block-size="20" activeColor="#00b1ff"
								:disabled="!item.isPlay" style="margin: 20rpx;"></slider>
						</view>
						<view class="action" style="width: auto;">
							<view class="text-grey text-xs">{{!!item.currentTime?item.currentTime:'00:00'}} /
								{{!!item.miDuration?item.miDuration:"未知"}}
							</view>
							<view class="text-grey text-xs">{{item.miSize}}</view>
						</view>
					</view>
				</view>
			</block>
			<block v-else-if="item.miType==4">
				<view style="width:100%;">

					<view class="hxt-flex" style="background-color:#000; position: relative; padding: 10rpx 6rpx;">
						<view class="hxt-flex-fill" style="color:#eee;font-size:20rpx;text-align:left;">
							{{item.miSize}}
						</view>
						<!-- <view class="cu-tag badge" style="width:40rpx;height:40rpx;top:-10rpx;right:-10rpx; z-index: 1;" @click="delvideo(index)">
								<text class="cuIcon-close" style="font-size:28rpx;"></text>
							</view> -->
					</view>
					<view style="padding-top:100%;position:relative;background-color:#000;">
						<video :src="item.rawUrl" direction="0" controls enable-play-gesture
							style="position:absolute;width:100%;height:100%;left:0;top:0;z-index: 0;"></video>
					</view>
				</view>
			</block>
			<block v-else-if="item.miType==7">
				<view class="cu-list menu-avatar padding-top-xs" style="overflow-x: hidden; overflow-y: auto;">
					<view class="cu-item" @click="previewFile(item)"
						style="background: #f3f3f3; border-radius: 8rpx; margin: 8rpx 0; height: 100rpx;">
						<view class="cu-avatar" style="background-color: #f3f3f3;">
							<i :class="[getFileIco(item.miTitle),'text-blue']"
								style="font-size: 64rpx;margin-right: 12rpx;"></i>
						</view>
						<view class="content" style="left: 115rpx;">
							<view class="text-black">
								<text class="text-cut"> {{item.miTitle}}</text>
							</view>
							<view class="text-gray text-sm flex">
								<text class="text-cut">(点击预览)</text>
							</view>
						</view>
						<view class="action">
							<view class="text-grey text-xs">{{item.miSize}}</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="hxt-flex padding padding-tb-sm">
			<view class="hxt-flex-fill">
				<view @click="addMedia({type:1})" class="cu-capsule">
					<view class="cu-tag bg-blue sm">
						<text class="fa fa-file-text-o"></text>
					</view>
					<view class="cu-tag line-blue sm">文字</view>
				</view>
				<view @click="sheetFile({type:2})" class="cu-capsule">
					<view class="cu-tag bg-blue sm">
						<text class="fa fa-file-image-o"></text>
					</view>
					<view class="cu-tag line-blue sm">图片</view>
				</view>
				<view @click="sheetFile({type:3})" class="cu-capsule">
					<view class="cu-tag bg-blue sm">
						<text class="fa fa-file-audio-o"></text>
					</view>
					<view class="cu-tag line-blue sm">音频</view>
				</view>
				<view @click="sheetFile({type:4})" class="cu-capsule">
					<view class="cu-tag bg-blue sm">
						<text class="fa fa-file-video-o"></text>
					</view>
					<view class="cu-tag line-blue sm">视频</view>
				</view>
				<view @click="sheetFile({type:7})" class="cu-capsule">
					<view class="cu-tag bg-blue sm">
						<text class="fa fa-file-pdf-o"></text>
					</view>
					<view class="cu-tag line-blue sm">文件</view>
				</view>
			</view>
		</view>
		<!-- 录音弹框 -->
		<view class="cu-modal show bottom-modal" style="padding: 0;text-align: center;" v-if="loadModal">
			<view class="cu-dialog" style="padding: 35rpx 0;">
				<view v-if="audioIsStart" class='text-red text-sm'>正在录音, 时长剩余约 {{countDownNum}} 秒</view>
				<view v-if="!audioIsStart" class='text-red text-sm'>您可录制不超过 {{countDownNum}} 秒的录音</view>
				<text class="cuIcon-voice" @longpress="startRecord" @touchend="endloadModal"
					style="font-size: 200rpx;"></text>
				<view style="color:#000;">按住录音</view>
				<view style="margin-top: 50rpx;color:#000;" @click="closeloadModal">取消</view>
			</view>
		</view>
	</block>
</template>

<script>
	import * as hxt from "@/utils/hxt.js";

	const recorderManager = wx.getRecorderManager();
	export default {
		name: "editMedia",
		destroyed: function() {
			var _this = this,
				innerAudioContext = _this.innerAudioContext;
			try {
				if (innerAudioContext && !innerAudioContext.paused) {
					innerAudioContext.pause();
				}
			} catch (e) {}
		},
		options: {
			styleIsolation: 'apply-shared'
		},
		props: {
			value: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				mediaList: [],
				//音频
				innerAudioContext: null,
				audioId: -1,
				//视频
				fullScreen: false,
				show: false,
				//录音
				loadModal: false,
				timer: null, //计时器名字
				countDownNum: 60, //录音时长
				audioIsStart: false, //录音是否开始	
				opt: null,
			};
		},
		computed: {
			// mediaList: {
			// 	get: function() {
			// 		var v = this.value;
			// 		if (!hxt.isArray(v)) v = [];
			// 		return v;
			// 	},
			// 	set: function(val) {
			// 		this.$emit('input', val);
			// 	}
			// },
			isAndroid: function() {
				const info = wx.getSystemInfoSync();
				if (info.platform === 'android') {
					return true;
				}
				return false;
			}
		},
		watch: {
			value: {
				handler(news, olds) {
					if (hxt.isArray(news)) this.mediaList = news;
				},
				deep: true // 开启深度监听
			},
			mediaList: {
				handler(newVal, oldVal) {
					this.$emit('update', newVal);
				},
				deep: true // 开启深度监听
			}
		},
		created() { //组件创建后，但还未挂载
			var _this = this;
			_this.mediaList=_this.value;
		},
		methods: {
			Notify: function(msg) {
				Notify({
					type: 'warning',
					message: msg
				});
			},
			addAudioEvent: function() {
				var _this = this,
					innerAudioContext = _this.innerAudioContext;
				if (!innerAudioContext) return;

				var getpaused = function() {
					setTimeout(() => { //解决onTimeUpdate第二次播放不会触发的坑
						var paused = innerAudioContext.paused;
					}, 100);
				};
				innerAudioContext.onCanplay(getpaused);
				innerAudioContext.onSeeking(getpaused);
				innerAudioContext.onPlay(() => {
					console.log('audioId', _this.audioId)
					hxt.loading(false);
					_this.mediaList[_this.audioId].isPlay = true;
				});

				innerAudioContext.onPause(() => {
					_this.mediaList[_this.audioId].isPlay = false;
				});
				innerAudioContext.onEnded(function(res) {
					console.log('播放失败', res)
					_this.mediaList[_this.audioId].isPlay = false;
					_this.mediaList[_this.audioId].value = 0;
					_this.mediaList[_this.audioId].currentTime = '00:00';
					// _this.$forceUpdate();
				});

				innerAudioContext.onTimeUpdate(() => {
					_this.mediaList[_this.audioId].value = parseInt(parseInt((innerAudioContext.currentTime /
						innerAudioContext.duration) * 100));
					_this.mediaList[_this.audioId].currentTime = hxt.formatSeconds(innerAudioContext
						.currentTime);
					_this.mediaList[_this.audioId].miTitle = hxt.formatSeconds(innerAudioContext.duration);
				});

				innerAudioContext.onError((res) => {
					hxt.loading(true);
					hxt.alert(res.errMsg, '播放失败');
					_this.mediaList[_this.audioId].isPlay = false;
					_this.mediaList[_this.audioId].value = 0;
					_this.mediaList[_this.audioId].currentTime = '00:00';
				});
			},
			playAudio: function(index) {
				var _this = this,
					audioItem = _this.mediaList[index],
					innerAudioContext = _this.innerAudioContext;

				if (!innerAudioContext) {
					innerAudioContext = wx.createInnerAudioContext();
					_this.setData({
						innerAudioContext: innerAudioContext
					});
					_this.addAudioEvent();
				}

				if (audioItem.isPlay) {
					innerAudioContext.pause();
					_this.mediaList[index].isPlay = false;
				} else {
					if (index != _this.audioId) {
						if (_this.audioId != -1) {
							_this.mediaList[_this.audioId].isPlay = false;
							_this.mediaList[_this.audioId].value = 0;
							_this.mediaList[_this.audioId].currentTime = '00:00';
						};
						_this.setData({
							audioId: index
						});

						innerAudioContext.src = encodeURI(!!audioItem.rawUrl ? audioItem.rawUrl : audioItem
							.miUrl); //天坑：IOS下url含有空格无法播放					
						innerAudioContext.autoplay = true;
						hxt.loading(true);
					} else {
						innerAudioContext.play();
						_this.mediaList[_this.audioId].isPlay = true;
					}
				}
				// _this.$forceUpdate();
			},
			swiperChange(e) { //音频播放快进
				var _this = this,
					innerAudioContext = _this.innerAudioContext;
				var value = e.detail.value;
				var sk = innerAudioContext.duration * (value / 100);
				innerAudioContext.seek(sk);
				_this.$set(_this.mediaList[_this.audioId], 'currentTime', hxt.formatSeconds(sk));
			},
			showVideo: function(obj, index) { //弹出视频图层播放视频
				var _this = this,
					id = 'video-' + index;

				if (_this.audioId > -1 && _this.mediaList[_this.audioId].isPlay) {
					_this.innerAudioContext.pause();
					_this.mediaList[index].isPlay = false;
				}

				wx.getSystemInfo({
					success: function(res) {
						if (res.platform == "android") {
							_this.videoContext = wx.createVideoContext(id, _this);
							_this.videoContext.requestFullScreen();
							_this.fullScreen = true;
						} else {
							wx.previewMedia({
								sources: [{
									url: obj.miUrl,
									type: 'video',
									poster: obj.miUrl +
										'?x-oss-process=video/snapshot,t_100,f_png,m_fast,ar_auto'
								}]
							});
						}
					}
				});
			},
			screenChange: function(e) { //视频退出 /进入全屏				
				var _this = this,
					fullScreen = e.detail.fullScreen; //值true为进入全屏，false为退出全屏
				if (!fullScreen) { //退出全屏
					_this.videoContext.stop();
					_this.fullScreen = false;
				} else { //进入全屏
					_this.videoContext.play();
					_this.fullScreen = true;
				}
			},
			closeVideo: function(e) { //视频退出全屏			
				this.videoContext.exitFullScreen();
				this.setDatafullScreen = false;
			},
			previewFile: function(item) { //文件预览
				var _this = this;
				if (!item.rawUrl) return;
				var ext = hxt.getFileExt(item.rawUrl);
				wx.openDocument({
					filePath: item.rawUrl,
					fileType: ext, // 文档打开格式记得写上，否则可能不能打开文档, 文档类型只能是一个；
					success: function(res) { //console.log('打开文档成功') 
					},
					fail: function(res) {
						hxt.alert(res.errMsg, "预览失败");
					}
				});
			},
			getFileIco: function(name) { //文件类型图标
				return hxt.getFileIco(name);
			},
			getFileSize: function(size) { //文件大小
				return hxt.getFileSize(size);
			},
			getApplyTypeStr: function(e) {
				return e == 1 ? '文字' : e == 2 ? '图片' : e == 3 ? '音频' : e == 4 ? '视频' : e == 7 ? '文件' : e == 8 ? '签名' :
					'';
			},
			getValue: function(val) {
				return (val == undefined || val == null ? '' : val + '').replace(/\s+/g, '');
			},
			mediaChange: function(type, item, idx) { //内容事件
				var _this = this,
					mediaList = _this.mediaList;
				if (type == 'up' || type == 'down') {
					var way = type == 'up' ? 1 : 2;
					if ((way == 1 && idx == 0) || (way == 2 && idx == mediaList.length - 1)) return;
					//way == 1 ? '上移' : '下移';
					var ix = way == 1 ? idx - 1 : idx + 1;
					mediaList.splice(idx, 1);
					mediaList.splice(ix, 0, item);
					//_this.getNumber(1);
				} else if (type == 'del') {
					mediaList.splice(idx, 1);
					return;
					hxt.confirm('确定删除【' + _this.getApplyTypeStr(item.miType) + '】内容？', '提示',
						function() {
							mediaList.splice(idx, 1);
							//_this.getNumber(1);
						});
				}
				//this.$emit('update', mediaList);
			},
			addMedia: function(e, values) { //添加内容项
				var _this = this,
					mediaList = _this.mediaList,
					_default = {
						miId: 0,
						miType: 0,
						miTitle: '',
						miDesc: '',
						miUrl: '',
						rawUrl: null,
						miIndex: 0,
						isPlay: false,
						currentTime: '',
						value: 0,
						thumb: ""
					},
					clone = function(data) {
						return JSON.parse(JSON.stringify(data));
					};
				e = e || {};
				var o = null;
				if (e.type == 1) {
					o = hxt.extend(clone(_default), {
						miType: 1
					});
				} else if (e.type == 2 || e.type == 3 || e.type == 4 || e.type == 7) {
					o = hxt.extend(clone(_default), values);
				}
				if (!!o) {
					if (!e.item) mediaList.push(o);
					else mediaList.splice(e.index, 0, o);
				}
				//this.$emit('update', mediaList);
			},
			sheetFile: function(e) { //选择图片/音频/视频/文件
				var _this = this,
					type = e.type;
				if (type == 2) {
					wx.chooseMedia({
						mediaType: ['image'],
						sourceType: ['album', 'camera'], //视频来源album==相册，camera==相机						
						camera: 'back',
						success(res) {
							if (res.tempFiles.length < 1) return;
							res.tempFiles.forEach(function(item,index){
								if (item.size > 10485760) {
									hxt.alert('图片最大不可超过10M');
									return;
								};
								_this.addMedia(e, {
									miType: 2,
									miUrl: "",
									rawUrl: item.tempFilePath,
									miSize: hxt.getFileSize(item.size)
								});
							});
						},
						fail: function(err) {
							hxt.hideLoading();
							// if (err.errMsg == "chooseVideo:fail user cancel") return;
							// hxt.alert(err.errMsg);
						}
					});
				} else if (type == 3) {
					wx.showActionSheet({
						itemList: ['录制', '从文件中选择'],
						success(res) {
							if (res.tapIndex == 0) {
								_this.setData({
									opt: e,
									loadModal: true,
									countDownNum: 60,
									audioIsStart: false
								});
							};
							if (res.tapIndex == 1) {
								wx.chooseMessageFile({
									count: 10,
									type: 'file',
									extension: [".mp3", "mp3"],
									success(res) {
										if (res.tempFiles.length < 1) return;
										res.tempFiles.forEach(function(mp3,index){
											console.log(mp3)
											if (mp3.size > 20971520) {
												hxt.alert('音频最大不可超过20M');
												return;
											};
											_this.addMedia(e, {
												miType: 3,
												miUrl: "",
												rawUrl: mp3.path,
												miTitle: mp3.name,
												miSize: hxt.getFileSize(mp3.size),
												miDuration: hxt.getDuration(mp3.time / 1000)
											});
										});
									},
									fail(err) {
										console.log("select file mp3 err:{0}".xFormat(err))
									}
								});
							};
						},
						fail(res) {
							console.log("showActionSheet err:{0}".xFormat(res.errMsg));
						}
					});
				} else if (type == 4) {
					wx.chooseMedia({
						mediaType: ['video'],
						sourceType: ['album', 'camera'], //视频来源album==相册，camera==相机
						maxDuration: 60, //拍摄视频最长拍摄时间，单位秒
						camera: 'back',
						success(res) {
							//console.log('压缩前', res);
							if (res.tempFiles.length < 1) return;
							hxt.showLoading('加载中');
							res.tempFiles.forEach(function(video,index){
								wx.getVideoInfo({
									src: video.tempFilePath,
									success: function(ret) {
										var resolution = 1920 / Math.max(ret.width, ret.height);
										//console.log('压缩前视频信息', ret);
										// if (video.duration > 30) {
										// 	hxt.hideLoading();
										// 	hxt.alert('视频时长不能超过30秒');
										// 	return;
										// };
										if (ret.size < 10485760) {
											hxt.hideLoading();
											_this.addMedia(e, {
												miType: 4,
												miUrl: "",
												rawUrl: video.tempFilePath,
												miDuration: hxt.getDuration(video.duration),
												miTitle: '',
												miSize: hxt.getFileSize(video.size)
											});
											return;
										};
										if (ret.size * 1024 > 209715200) {
											hxt.hideLoading();
											hxt.alert('视频最大不可超过200M');
											return;
										};
										if (ret.size > 104857600 || ret.height > 1920 || ret.width >
											1920) { //100M
											hxt.hideLoading();
											wx.showModal({
												title: '提示',
												content: '视频大于100M或者是分辨率过高，压缩需要耗费大量时间，是否确定要压缩？',
												success(a) {
													if (a.confirm) {
														hxt.showLoading('压缩中...')
														var fps = ret.fps;
														if (fps > 30) {
															fps = 30;
														}
														wx.compressVideo({
															src: video.tempFilePath,
															//quality: 'high', //'low':低，'medium':中，'high':高  
															bitrate: 2600,
															fps: fps,
															resolution: Number(
																resolution.toFixed(
																	1)),
															complete: function() {
																hxt.hideLoading();
															},
															success: function(r) {
																console.log(r);
																_this.addMedia(e, {
																	miType: 4,
																	miUrl: "",
																	rawUrl: r
																		.tempFilePath,
																	miTitle: '',
																	miDuration: hxt
																		.getDuration(
																			r
																			.duration
																		),
																	miSize: hxt
																		.getFileSize(
																			r
																			.size
																		)
																});
															},
															fail: function(err) {
																hxt.hideLoading();
																hxt.alert(err
																	.errMsg,
																	'视频压缩失败');
															}
														});
														return;
													} else if (a.cancel) {
														hxt.hideLoading();
														//console.log('用户点击取消');
													}
												}
											})
										} else {
											var fps = ret.fps;
											if (fps > 30) {
												fps = 30;
											}
											//符合标准，压缩视频	
											hxt.showLoading('压缩中...');
											wx.compressVideo({
												src: video.tempFilePath,
												//quality: 'high', //'low':低，'medium':中，'high':高  
												bitrate: 2600,
												fps: fps,
												//  resolution:0.5,
												complete: function() {
													hxt.hideLoading();
												},
												success: function(r) {
													console.log(r);
													_this.addMedia(e, {
														miType: 4,
														miUrl: "",
														rawUrl: r.tempFilePath,
														miTitle: '',
														miDuration: hxt
															.getDuration(r
																.duration),
														miSize: hxt.getFileSize(r
															.size)
													});
												},
												fail: function(err) {
													hxt.alert(err.errMsg, '视频压缩失败');
												}
											});
										};
									},
									fail: function(err) {
										hxt.hideLoading();
										hxt.alert(err.errMsg);
									}
								});
							});
							
						},
						fail: function(err) {
							hxt.hideLoading();
							// if (err.errMsg == "chooseVideo:fail user cancel") return;
							// hxt.alert(err.errMsg);
						}
					});

				} else if (type == 7) { //选择文件
					wx.chooseMessageFile({
						count: 10,
						type: 'file',
						success(res) {
							//console.log(res);
							if (res.tempFiles.length < 1) return;
							res.tempFiles.forEach(function(item,index){
								if (item.size > 209715200) {
									hxt.hideLoading();
									hxt.alert('文件最大不可超过200M');
									return;
								};
								_this.addMedia(e, {
									miType: 7,
									miUrl: "",
									rawUrl: item.path,
									miSize: hxt.getFileSize(item.size),
									miTitle: item.name
								});
							});
							
						}
					});
				}
			},
			startRecord() { //开始录音
				var _this = this;
				const options = {
					duration: 60000, //控制录音时长
					sampleRate: 44100, //采样率
					numberOfChannels: 2,
					encodeBitRate: 320000,
					format: 'mp3',
					frameSize: 200,
					audioSource: 'auto',
					success(res) {
						console.log(res)
					}
				}
				wx.getSetting({
					success(res) {
						if (res.authSetting['scope.record']) {
							recorderManager.onStart((res) => {
								console.log('recorderManager.onStart');
								wx.showLoading({
									title: '正在录音...'
								});
								var timer = setInterval(function() {
									_this.setData({
										countDownNum: _this.countDownNum - 1
									});
									if (_this.countDownNum == 0) {
										_this.stopRecord();
									}
								}, 1000);
								_this.setData({
									audioIsStart: true,
									timer: timer
								});
							});
							//错误回调
							recorderManager.onError((res) => {
								hxt.alert(res.errMsg, '录音失败');
								_this.setData({
									loadModal: false,
									audioIsStart: false
								});
							});
							recorderManager.start(options);
						} else {
							wx.authorize({
								scope: 'scope.record',
								success: function(r) {
									hxt.toast('授权成功，请长按开始录音。');
								},
								fail: function(r) {
									hxt.alert('未授权录音，您将不能使用录音功能。前往设置打开录音权限。', '授权失败', function(e) {
										uni.openSetting();
									});
								}
							})
						}
					}
				})
			},
			endloadModal(e) { //结束长按
				this.stopRecord();
			},
			closeloadModal() { //录音的取消
				this.setData({
					loadModal: false
				});
			},
			stopRecord() { //停止录音
				var _this = this;
				if (!!_this.timer) {
					clearInterval(_this.timer);
					_this.setData({
						timer: null
					});
				}
				if (!_this.audioIsStart) {
					hxt.toast('请长按开始录音');
					return;
				}
				recorderManager.onStop((res) => {
					wx.hideLoading();
					console.log('停止录音', res);
					_this.addMedia(_this.opt, {
						miType: 3,
						miUrl: "",
						rawUrl: res.tempFilePath,
						miTitle: '',
						miDuration: hxt.getDuration(res.duration / 1000),
						miSize: hxt.getFileSize(res.fileSize)
					});
					_this.setData({
						loadModal: false,
						audioIsStart: false
					})
				});
				recorderManager.stop();
			},
		}
	}
</script>

<style>
	.hxt-card {
		padding: 20rpx 0;
	}

	.tn-lazy-load__container {
		text-align: center;
	}

	.input-class {
		font-size: 28rpx;
		color: #606266 !important;
	}

	.hxt-card+.hxt-card {
		border-top: 1rpx solid #eee;
	}

	.btn {
		text-align: center;
		padding: 5rpx 20rpx;
		border-right: 2rpx solid #f1f1f1;
		color: #606266;
		display: inline-block;
		font-size: 24rpx;
	}

	.btn:last-child {
		border: 0;
	}

	.md-tag .cu-capsule {
		display: block;
		padding: 12rpx 20rpx;
	}
</style>